const util = require('../../../utils/util.js');
const api = require('../../../config/api.js');
var app = getApp();
Page({
  data: {
    detail: {},
    dmvId: 0,
    page: 1,
    activeIndex: 0,
    navbar_bgcolor: wx.getStorageSync('navbar_bgcolor'),
    tabIndex: 1,
    latitude: 23.099994,
    longitude: 113.324520,
    markers: [{
      iconPath: "/style/images/location.png",
      latitude: 23.099994,
      longitude: 113.324520,
      width: 50,
      height: 50,
      title:''
    }],
    subKey: 'B5QBZ-7JTLU-DSSVA-2BRJ3-TNXLF-2TBR7',
    enable3d: false,
    showCompass: true,
    enableOverlooking: false,
    enableZoom: true,
    enableScroll: true,
    enableRotate: false,
    drawPolygon: false,
    enableSatellite: false,
    enableTraffic: false

  },

  onLoad: function (param) {
    this.data.dmvId = param.id;
    this.getDetail();
  },
  getDetail() {
    wx.showLoading({
      title: '加载中',
    });
    
    let that = this;
    util.request(api.SchoolDetail, {
      id: that.data.dmvId
    }).then(function (res) {
      //console.log(JSON.stringify(res));
      if (res.errno === 0) {
        var detail = res.data.detail;

        var longitudeVal = 'markers[0].longitude';
        var latitudeVal = 'markers[0].latitude';
        var nameVal = 'markers[0].title'

        that.setData({
          detail: detail,
          longitude: detail.longitude,
          latitude: detail.latitude,
          [longitudeVal]: detail.longitude,
          [latitudeVal]: detail.latitude,
          [nameVal]: detail.name
        });
      }

      wx.hideLoading();
    });
  },

  toMap: function () {
    wx.navigateTo({
      url: 'url',
    })
  },

  tabClick: function (e) {
    this.setData({
      //activeIndex: e.currentTarget.id
      tabIndex: e.currentTarget.id
    });
  },

  onShareAppMessage: function (res) {
  },
  onPullDownRefresh: function () {
  }
  ,
  //地图跳转
  fnMap: function (e) {
    var location = e.currentTarget.dataset.location;
  },
  parseFloatNum(x) {

    let xFloat = []

    xFloat = x.toString().split('.')[1]

    return Number.parseFloat(x).toFixed(xFloat.length)

  }

})